<template>
  <el-descriptions :column="1">
    <template v-slot:title>
      <span class="personal-info-edit-title">基本信息</span>
      <span class="personal-info-edit-button">
        <el-button size="mini" @click="edit">编辑信息</el-button>
      </span>
    </template>
    <el-descriptions-item label="用户名称">{{userInfo.userName}}</el-descriptions-item>
    <el-descriptions-item label="真实姓名">{{userInfo.realName}}</el-descriptions-item>
    <el-descriptions-item label="联系方式">{{userInfo.phone}}</el-descriptions-item>
    <el-descriptions-item label="邮箱地址">{{userInfo.email}}</el-descriptions-item>
    <el-descriptions-item label="所属部门">
      <div v-if="userInfo.organizations && userInfo.organizations.length > 0">
        <p style="margin: 0" v-for="item of userInfo.organizations">{{item.orgName}}</p>
      </div>
      <span v-else>没有所属组织</span>
    </el-descriptions-item>
    <el-descriptions-item label="创建时间">{{userInfo.createdTime}}</el-descriptions-item>
  </el-descriptions>
</template>

<script>
  import {userOneself} from '@/api/oneseIf-centre'

  /**
   *{ 个人基本信息 }
   * @param:
   * @author: 宋康
   * @DateTime: 2022/7/1
   */
  export default {
    name: "PersonalBasicInfo",
    data() {
      return {
        userInfo: {
          uid: "",
          loginName: "",
          userName: "",
          realName: "",
          phone: "",
          email: "",
          organizations: null,
          createdTime: "",
        }
      }
    },
    methods: {
      /**
       *{ 编辑 }
       * @author: 宋康
       * @DateTime: 2022/7/1
       */
      edit() {
        this.$router.push({
          name: 'PersonalBasicInfoEdit'
        })
      },
      /**
       * 查询个人信息
       */
      queryUserOneself() {
        userOneself().then(res => {
          if (res.status && res.data) {
            this.userInfo = {
              ...res.data
            }
          }
        })
      }
    },
    mounted() {
      this.queryUserOneself()
    }
  }
</script>

<style lang="scss" scoped>
  .personal-info-edit-title {
    font-size: 18px;
  }

  .personal-info-edit-button {
    margin-left: 0.1042rem;

    &::v-deep .el-button--mini, .el-button--mini.is-round {
      padding: 4px 10px;
    }
  }
</style>
